package org.gos.mission.service;

import java.sql.Connection;
import java.util.List;

import org.gos.mission.dao.LoginDaoMySQLImpl;
import org.gos.mission.dao.MissionDaoMySQLImpl;
import org.gos.mission.domain.Mission;
import org.gos.mission.domain.User;
import org.gos.mission.util.DB;

public class MissionServiceImpl implements MissionService {

	private MissionDaoMySQLImpl missionDao;

	private static MissionServiceImpl msi ;
	
	public MissionServiceImpl() {
		missionDao = new MissionDaoMySQLImpl();
	}
	
	public static MissionService getMissionService() {
		if(msi == null){
			
			msi = new MissionServiceImpl();
			
		}
		return msi;
	}
	
	public void add(Mission mission) {
		Connection conn = null;
		try {
			conn = DB.getConnection(ServiceManager.DB_CONNECTION);
			missionDao.add(conn,mission);
		} finally {
			DB.close(conn);
		}
	}

	public List<Mission> getMissionsByUser(User user) {
		Connection conn = null;
		try {
			conn = DB.getConnection(ServiceManager.DB_CONNECTION);
			return missionDao.getMissionsByUser(conn,user);
		} finally {
			DB.close(conn);
		}
	}

}
